package com.shenmazong.library.controller;

import com.shenmazong.library.entity.TbTaskChapter;
import com.shenmazong.library.entity.TbTaskSkillDetail;
import com.shenmazong.library.entity.TbTaskSkillLibrary;
import com.shenmazong.library.entity.TbTaskTheoryLibrary;
import com.shenmazong.library.service.TaskLibraryService;
import com.shenmazong.manage.entity.TbTaskTheoryTemplate;
import com.shenmazong.util.OssUploadTemplate;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import com.shenmazong.vo.ListParamVo;
import com.shenmazong.vo.RandomTheoryVo;
import com.shenmazong.vo.TaskTheoryListVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;


/**
 * @description 作业库管理控制层
 * @author Qi
 * @date 2021/9/18 17:08
 * @version 1.0
 */

@Api(tags = "作业库管理")
@RestController
@RequestMapping("library")
public class TaskLibraryController {

    @Autowired
    private TaskLibraryService libraryService;
    @Autowired
    private OssUploadTemplate ossUploadTemplate;
    
    /**
     * @description 在线录入理论题目
     * @params [taskTheoryListVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:29
     */
    @PostMapping("onLineInputTaskTheory")
    public ResultResponse onLineInputTaskTheory(@RequestBody TaskTheoryListVo taskTheoryListVo){
        return libraryService.onLineInputTaskTheory(taskTheoryListVo);
    }
    
    /**
     * @description 读取Excel文件内容 返回数据集合
     * @params [file]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:30
     */
    @PostMapping("uploadFileInputTaskTheory")
    public ResultResponse uploadFileInputTaskTheory(MultipartFile file) throws IOException {
        return libraryService.uploadFileInputTaskTheory(file);
    }
    
    /**
     * @description 理论作业修改
     * @params [tbTaskTheoryLibrary]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:30
     */
    @PostMapping("updateTaskTheory")
    public ResultResponse updateTaskTheory(@RequestBody TbTaskTheoryLibrary tbTaskTheoryLibrary){
        return libraryService.updateTaskTheory(tbTaskTheoryLibrary);
    }
    
    /**
     * @description 理论作业批量删除
     * @params [chooseIdVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:30
     */
    @PostMapping("deleteTaskTheoryByTheoryIds")
    public ResultResponse deleteTaskTheoryByTheoryIds(@RequestBody BatchChooseIdVo chooseIdVo){
        return libraryService.deleteTaskTheoryByTheoryIds(chooseIdVo);
    }

    /**
     * @description 通过课程ID批量删除理论作业
     * @params [chooseIdVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:30
     */
    @PostMapping("deleteTaskTheoryByCourseIds")
    public ResultResponse deleteTaskTheoryByCourseIds(@RequestBody BatchChooseIdVo chooseIdVo){
        return libraryService.deleteTaskTheoryByCourseIds(chooseIdVo);
    }

    /**
     * @description 通过章节ID批量删除理论作业
     * @params [chooseIdVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:30
     */
    @PostMapping("deleteTaskTheoryByChapterIds")
    public ResultResponse deleteTaskTheoryByChapterIds(@RequestBody BatchChooseIdVo chooseIdVo){
        return libraryService.deleteTaskTheoryByChapterIds(chooseIdVo);
    }
    
    /**
     * @description 题库列表
     * @params [paramVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:34
     */
    @PostMapping("listTaskTheoryLibrary")
    public ResultResponse listTaskTheoryLibrary(@RequestBody ListParamVo paramVo){
        return libraryService.listTaskTheoryLibrary(paramVo);
    }

    /**
     * @description 根据ID获取理论题库内容
     * @params [taskTheoryLibrary]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:35
     */
    @PostMapping("getTaskTheoryById")
    public ResultResponse getTaskTheoryById(@RequestBody TbTaskTheoryLibrary taskTheoryLibrary){
        return libraryService.getTaskTheoryById(taskTheoryLibrary);
    }

    /**
     * @description 技能作业库新增
     * @params [tbTaskSkillLibrary]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:39
     */
    @PostMapping("saveTaskSkillLibrary")
    public ResultResponse saveTaskSkillLibrary(@RequestBody TbTaskSkillLibrary tbTaskSkillLibrary){
        return libraryService.saveTaskSkillLibrary(tbTaskSkillLibrary);
    }

    /**
     * @description 技能作业库批删
     * @params [chooseIdVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:43
     */
    @PostMapping("deleteTaskSkillBySkillId")
    public ResultResponse deleteTaskSkillBySkillId(@RequestBody BatchChooseIdVo chooseIdVo){
        return libraryService.deleteTaskSkillBySkillId(chooseIdVo);
    }

    /**
     * @description 技能作业库修改
     * @params [tbTaskSkillLibrary]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:43
     */
    @PostMapping("updateTaskSkillLibrary")
    public ResultResponse updateTaskSkillLibrary(@RequestBody TbTaskSkillLibrary tbTaskSkillLibrary){
        return libraryService.updateTaskSkillLibrary(tbTaskSkillLibrary);
    }

    /**
     * @description 技能作业库列表
     * @params [paramVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:43
     */
    @PostMapping("listTaskSkillLibrary")
    public ResultResponse listTaskSkillLibrary(@RequestBody ListParamVo paramVo){
        return libraryService.listTaskSkillLibrary(paramVo);
    }

    /**
     * @description 技能作业明细批量新增
     * @params [detailList]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:51
     */
    @PostMapping("saveTaskSkillDetail")
    public ResultResponse saveTaskSkillDetail(@RequestBody List<TbTaskSkillDetail> detailList){
        return libraryService.saveTaskSkillDetail(detailList);
    }

    /**
     * @description 技能作业明细批量删除
     * @params [chooseIdVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:53
     */
    @PostMapping("deleteTaskSkillDetail")
    public ResultResponse deleteTaskSkillDetail(@RequestBody BatchChooseIdVo chooseIdVo){
        return libraryService.deleteTaskSkillDetail(chooseIdVo);
    }

    /**
     * @description 技能作业明细修改
     * @params [tbTaskSkillDetail]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:54
     */
    @PostMapping("updateTaskSkillDetail")
    public ResultResponse updateTaskSkillDetail(@RequestBody TbTaskSkillDetail tbTaskSkillDetail){
        return libraryService.updateTaskSkillDetail(tbTaskSkillDetail);
    }

    /**
     * @description 技能作业明细列表
     * @params [paramVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:54
     */
    @PostMapping("listTaskSkillDetail")
    public ResultResponse listTaskSkillDetail(@RequestBody ListParamVo paramVo){
        return libraryService.listTaskSkillDetail(paramVo);
    }

    /**
     * @description 作业章节新增
     * @params [tbTaskChapter]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:56
     */
    @PostMapping("saveTaskChapter")
    public ResultResponse saveTaskChapter(@RequestBody TbTaskChapter tbTaskChapter){
        return libraryService.saveTaskChapter(tbTaskChapter);
    }

    /**
     * @description 作业章节批删
     * @params [chooseIdVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:58
     */
    @PostMapping("deleteTaskChapter")
    public ResultResponse deleteTaskChapter(@RequestBody BatchChooseIdVo chooseIdVo){
        return libraryService.deleteTaskChapter(chooseIdVo);
    }

    /**
     * @description 作业章节修改
     * @params [tbTaskChapter]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:59
     */
    @PostMapping("updateTaskChapter")
    public ResultResponse updateTaskChapter(@RequestBody TbTaskChapter tbTaskChapter){
        return libraryService.updateTaskChapter(tbTaskChapter);
    }

    /**
     * @description 作业章节列表
     * @params [paramVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 9:59
     */
    @PostMapping("listTaskChapter")
    public ResultResponse listTaskChapter(@RequestBody ListParamVo paramVo){
        return libraryService.listTaskChapter(paramVo);
    }

    /**
     * @description 获取所有作业章节
     * @params []
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/19 10:35
     */
    @PostMapping("listAllTaskChapter")
    public ResultResponse listAllTaskChapter(){
        return libraryService.listAllTaskChapter();
    }

    /**
     * @description 根据ID获取理论作业内容
     * @params [tbTaskTheoryLibrary]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/21 14:58
     */
    @PostMapping("getTaskTaskTheory")
    public ResultResponse getTaskTaskTheory(@RequestBody TbTaskTheoryLibrary tbTaskTheoryLibrary){
        return libraryService.getTaskTaskTheory(tbTaskTheoryLibrary);
    }
    /**
     * @description 根据ID获取技能作业内容
     * @params [tbTaskSkillLibrary]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/21 14:58
     */
    @PostMapping("getTaskTaskSkill")
    public ResultResponse getTaskTaskSkill(@RequestBody TbTaskSkillLibrary tbTaskSkillLibrary){
        return libraryService.getTaskTaskSkill(tbTaskSkillLibrary);
    }

    /**
     * @description 理论作业随机生成
     * @params [randomTheoryVo]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/22 18:53
     */
    @PostMapping("randomCreateTheory")
    public ResultResponse randomCreateTheory(@RequestBody RandomTheoryVo randomTheoryVo){
        return libraryService.randomCreateTheory(randomTheoryVo);
    }

    /**
     * @description //技能作业文档上传
     * @params [file]
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/26 8:27
     */
    @PostMapping("uploadSkillFile")
    public ResultResponse uploadSkillFile(MultipartFile file){
        return ossUploadTemplate.uploadFileObjectStorage(file);
    }

    //创建索引
    @PostMapping("createTheoryToEsIndex")
    public ResultResponse createTheoryToEsIndex(){
        return libraryService.createTheoryToEsIndex();
    }

    /**
     * @description 定时同步到es
     * @params []
     * @return com.shenmazong.utils.ResultResponse
     * @author Qi
     * @date 2021/9/29 8:02
     */
    @Scheduled(cron = "0 15 5 ? * *")
    @PostMapping("timingTheoryToEs")
    public void timingTheoryToEs(){
         libraryService.timingTheoryToEs();
    }

    //查询理论库列表通过es
    @PostMapping("listTaskTheoryLibraryByEs")
    public ResultResponse listTaskTheoryLibraryByEs(@RequestBody ListParamVo paramVo){
        return libraryService.listTaskTheoryLibraryByEs(paramVo);
    }

}




